package com.minyifang.wcspf.work.ui.home.presenter;

import com.minyifang.wcspf.common.base.BasePresenter;
import com.minyifang.wcspf.common.config.network.Constants;
import com.minyifang.wcspf.common.config.network.RetrofitHelper;
import com.minyifang.wcspf.common.config.user.UserManager;
import com.minyifang.wcspf.work.ui.home.view.SpecialSaleView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LuoYaWei on 2018/8/9.
 */
public class SpecialSalePresenter extends BasePresenter<SpecialSaleView> {
    public void getList(int pageIndex) {
        getView().showLoadingView();
        Map<String, Object> map = new HashMap<>();
        map.put("page", pageIndex);
        map.put("limit", 10);
        JSONObject jsonData = Constants.getJsonData(map, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());

        addTask(RetrofitHelper.getInstance().getService().getSpecialSaleGoodsList(requestBody), respond ->{
            getView().hideLoadingView();
            if (respond.result==1) {
                getView().showSpecialSaleGoodsList(respond.data);
            } else
                getView().showRequestFailed(respond.message);
        });
    }
}
